package com.qf.efserver.alarm.task;


import com.qf.common.core.entity.SleepSchedule;
import com.qf.efserver.alarm.service.SleepScheduleService;
import com.xxl.job.core.handler.annotation.XxlJob;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class DailyAlarmTask {

    @Autowired
    private SleepScheduleService sleepScheduleService;

    @Async
    @XxlJob("dailyAlarmCheck")
    public void executeDailyCheck() {
        List<SleepSchedule> validAlarms = sleepScheduleService.findValidAlarms();
        for (SleepSchedule alarm : validAlarms) {
//            registerTask(alarm);

        }

        List<SleepSchedule> expiredAlarms = sleepScheduleService.findExpiredAlarms();
        for (SleepSchedule expiredAlarm : expiredAlarms) {
            expiredAlarm.setStatus(0); // 设置为失效状态
            sleepScheduleService.update(expiredAlarm);
        }
    }

//    private void registerTask(SleepSchedule sleepSchedule) {
//        if (sleepSchedule != null) { // 检查 sleepSchedule 是否为空
//            SchedulingRunnable task = new SchedulingRunnable("sleepScheduleService", "pushOne", sleepSchedule);
//            // 需要添加执行任务的代码，例如：
//            task.run(); // 或者其他执行任务的方法
//        }
}
